#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T;
  cin >>T;
  while (T --) {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (auto &x : a) cin >> x;
    for (auto &x : b) cin >> x;
    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end());
    i64 total = accumulate(a.begin(), a.end(), 0ll) + accumulate(b.begin(), b.end(), 0ll);
    i64 cnt = 0;
    for (int l = 0, r = 0; l < n && r < n; l ++, r ++) {
      while (r < n && a[l] + b[r] < m) r ++;
      if (r < n) cnt ++;
    }
    cout << total - cnt * m << endl;
  }
}